import Vue from 'vue'
import { router } from './router'
import { store } from './store'
import { mixin, app } from './mixin'
import { fingerprint } from './utils/fingerprint'
import { widgets } from './components'
import App from './App.vue'
import './assets/app.css'
import './assets/animate.css'
import './utils/flexible'
import Vant, { Toast } from 'vant'
import 'vant/lib/index.css'
import VueClipboard from 'vue-clipboard2'
 
Vue.config.productionTip = false

const dev = process.env.NODE_ENV == 'development'

// 浏览器唯一标识 
fingerprint.get(uuid => {
  mixin.setData('clientId', uuid)
})

// 客服端ip和城市地域
const { cid, cip, cname } = window.returnCitySN;

// 获取appToken并保存

mixin.setData('token',app.getAppToken() || dev?'02b8e0aa-e7d6-44d5-bee2-d0f98a5f45ff':'')

Vue.mixin({ data: () => ({ cid, cip, cname, statusHeight: 0 }), methods: { ...mixin } })

// Vant组件
Vue.use(Vant)
Vue.use(Toast)
Vue.use(VueClipboard)


// 公共组件
for (let v in widgets) {
  Vue.component('v-' + v, widgets[v])
}

Vue.prototype.$bus = new Vue()
Vue.prototype.$app = app

// 路由监听
router.beforeEach(async (to, from, next) => {
  document.title = to.meta.title
  next()
})

// 初始化VUE
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
